package com.kristin.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class JedisSentinelClient {

    private static JedisSentinelPool jedisPool;

    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(10);
        config.setMinIdle(5);
        config.setMaxIdle(5);
        Set<String> sentinels = new HashSet<String>(Arrays.asList(
                "82.156.194.234:26001",
                "82.156.194.234:26002",
                "82.156.194.234:26003"
        ));
        // 设置哨兵信息
        jedisPool = new JedisSentinelPool("mymaster", sentinels, config, "kristin");
    }

    public static Jedis getResource() {
        return jedisPool.getResource();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            Jedis jedis = getResource();
//                System.out.println(jedis.del("key" + i , "value" + i));
//            System.out.println(jedis.get("key" + i));
            System.out.println(jedis.del("key" + i));

            jedis.close();
        }
    }

}
